<?php
/*
 * Created on 14.04.2007
 * @file: install.extensionicons.php
 * @author: Nikolai Plath
 */

function com_install()
{

global $database, $mosConfig_absolute_path, $mosConfig_lang;

	echo '<h2>Extension Icons</h2>';//no translation required ;)

	if (file_exists($mosConfig_absolute_path .'/administrator/components/com_extensionicons/language/'.$mosConfig_lang.'.php'))
	{
		require_once ($mosConfig_absolute_path .'/administrator/components/com_extensionicons/language/'.$mosConfig_lang.'.php');
	} else {
		require_once ($mosConfig_absolute_path .'/administrator/components/com_extensionicons/language/english.php');
	}

	/*
	 * Add new admin menu image
	 */
	$database->setQuery( "UPDATE #__components SET admin_menu_img = 'js/ThemeOffice/joomla_16x16.png' WHERE name= 'Extension Icons'");
	$database->query();

	echo _EXICONS_INSTALL_MENUIMAGE_CREATED . ' <img src="images/tick.png" /><br />';

	/*
	 * Add the Module
	 */
	if ( !is_writable ( "$mosConfig_absolute_path/administrator/modules/" ) )
	{
    	echo'
		<h2 style="color:red">There was a problem with your installation</h2>
      	<p>The directory "' . $mosConfig_absolute_path . '/administrator/modules/" is not writeable</p>
        <p>Please:</p>
        <ul>
        <li>Uninstall Extension Icons</li>
        <li>Modify the file permissions</li>
        <li>Reinstall</li>
        </ul>
        <br/>Thanks.</p>';
	   return false;
	}

	$database->setQuery( "INSERT INTO `#__modules` (`title`, `content`, `ordering`, `position`, `checked_out`, `checked_out_time`, `published`, `module`, `numnews`, `access`, `showtitle`, `params`, `iscore`, `client_id`)"
				." VALUES ('Extension Icons', '', 0, 'header', 0, '0000-00-00 00:00:00', 1, 'mod_extensionicons', 0, 99, 0, '', 0, 1);");
	$database->query();
	$moduleID = $database->insertid();
	$database->setQuery( "INSERT INTO `#__modules_menu` (`moduleid`, `menuid`) VALUES ($moduleID, 0);");
	$database->query();

	$adminDir = dirname(__FILE__);

    @rename( $adminDir . "/modules/mod_extensionicons.xml", "$mosConfig_absolute_path/administrator/modules/mod_extensionicons.xml");
    @rename( $adminDir . "/modules/mod_extensionicons.php", "$mosConfig_absolute_path/administrator/modules/mod_extensionicons.php");

	echo _EXICONS_INSTALL_MODULE_INSTALLED . ' <img src="images/tick.png" /><br />';

	/*
	 * Create directory for custom images
	 */
	@mkdir( "$mosConfig_absolute_path/images/ExtensionIcons_custom");

	echo _EXICONS_INSTALL_DIRECTORY_CREATED . ' <img src="images/tick.png" /><br />';

	/*
	 * Insert some Icons ;)
	 */
	$database->setQuery( "INSERT INTO `#__extension_icons`" .
	"\n (`id`, `name`, `parent`, `parent_name`, `admin_menu_link`, `admin_menu_alt`, `linkoption`, `ordering`, `admin_menu_img`, `published`)" .
	"\n VALUES" .
	"\n (1, 'Preview', 0, '', 'option=com_admin&amp;task=preview', 'Preview', 'com_admin', 1, 'js/ThemeOffice/preview.png', 1)," .
	"\n (2, 'Config', 0, '', 'option=com_config&amp;hidemainmenu=1', 'Config', 'com_config', 2, 'js/ThemeOffice/config.png', 1)," .
	"\n (3, 'Extension Icons', 0, '', 'option=com_extensionicons', 'Extension Icons', 'com_extensionicons', 3, 'js/ThemeOffice/joomla_16x16.png', 1);");
	$database->query();

	/*
	 * Thanx
	 */
	echo _EXICONS_INSTALL_THANK_YOU . '<img src="images/credits.png" /><br />';

	echo 'Made 2007 by <a href="http://www.nik-it.de">NiK-IT.de</a>';
}
?>
